﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace App
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            string username = this.txtLogin.Value.Trim();
            string password = this.txtPassword.Value.Trim();
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                return;
            }
            else
            {
                if (IsLogin(username, password))
                {
                    Session[EnumCollections.SESSION_LOGINNAME] = username;
                    Response.Redirect("~/admin/default.aspx");
                }
            }

        }

        private bool IsLogin(string username, string password)
        {
            bool result = false;
            string querySql = "SELECT Id,LoginName,LoginPwd FROM SysUser WHERE LoginName ='{0}' AND LoginPwd = '{1}'";

            querySql = string.Format(querySql, username, password);
            if (Common.FilterSqlCharacter(querySql))
            {
                return DbHelperSQLite.Exists(querySql);
            }
            else
            {
                //输入字符有误！
            }

            return result;
        }
    }
}